#include "gamehall.h"
#include "gameselect.h"
#include "ui_gamehall.h"
#include <QPainter>
#include <QIcon>
#include <QPushButton>
#include <QSound>

GameHall::GameHall(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::GameHall)
{
    ui->setupUi(this);

    // 设置窗口大小、图标、名字
    this->setFixedSize(1080,720);
    this->setWindowIcon(QIcon(":Resource/icon.png"));
    this->setWindowTitle("贪吃蛇大作战");

    // 设置开始按钮
    QFont font("华文行楷",18);
    QPushButton* pushButton_start = new QPushButton(this);
    pushButton_start->setText("开始游戏");
    pushButton_start->setFont(font);
    pushButton_start->move(520,400);
    pushButton_start->setGeometry(440,520,160,90);
    pushButton_start->setStyleSheet("QPushButton{border:0px;}");

    // 点击“开始游戏”按钮进入难度选择界面
    GameSelect* gameSelect = new GameSelect;
    connect(pushButton_start,&QPushButton::clicked,[=](){
       this->close();
       gameSelect->setGeometry(this->geometry());
       gameSelect->show();

       QSound::play(":Resource/clicked.wav");
    });
}

GameHall::~GameHall()
{
    delete ui;
}

void GameHall::paintEvent(QPaintEvent *event)
{
    (void) *event;
    // 实例化画家
    QPainter painter(this);

    // 实例化绘图设备
    QPixmap pix(":Resource/game_hall.png");

    // 绘图
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}

